package com.itcast.demoone

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.itcast.demoone.adapter.MyAdapter

class RecyclerViewActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_recycler_view)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        // 1. 获取组件
        val recyclerView = findViewById<RecyclerView>(R.id.recycler_view)

        // 3. 设置组件的布局管理器
        // 线性布局
        recyclerView.layoutManager = LinearLayoutManager(
            this,
            LinearLayoutManager.VERTICAL,
            false
        )

        // 宫格布局
        // recyclerView.layoutManager = GridLayoutManager(this, 3)

        // listOf('黑马程序员1', )
        val items = List(120){i -> "黑马程序员${i+1}"}

        // 2. 给组件设置适配器
        recyclerView.adapter = MyAdapter(items)

    }
}